import "./fix"
import _ from "./lodash.min.js"

const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const formatTimeHour = date => {
  const hour = date.getHours()
  const minute = date.getMinutes()
  // console.log(11,date,`${[hour, minute].map(formatNumber).join(':')}`)
  return `${[hour, minute].map(formatNumber).join(':')}`
}
const formatTimeDay = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  return `${[year, month, day].map(formatNumber).join('-')}`
}
const formatH = dates => {
  var date = new Date(dates);
  const hour = date.getHours()
  const minute = date.getMinutes()

  // return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  return [hour, minute].map(formatNumber).join(':')
}

const formatHt = dates => {
  var date = new Date(dates);
  const hour = date.getHours()
  // const minute = date.getMinutes()

  // return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  return hour
}

const formatHS = dates => {
  var date = new Date(dates);
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()

  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}
const formatDate = dates => {
  var date = new Date(dates);
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  return [year, month, day].map(formatNumber).join('-')
}
const formatDates = dates => {
  var date = new Date(dates);
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  return [year, month, day].map(formatNumber).join('-')+' '+'00:00'
}
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}
const dateListGet = dates => {
  var date = new Date(dates);
  let da = new Date(date.setDate(date.getDate() - 1))
  let res = _.times(7, (i) => {
    let dayInfo = da.setDate(da.getDate() + 1)
    return {
      date: new Date(dayInfo).getDate(),
      month: new Date(dayInfo).getMonth() + 1,
      week: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date(dayInfo).getDay()],
      day: new Date(dayInfo).getTime()
      // index:i
      // value: dayInfo.format('YYYY-MM-DD'),
      // disable: dayInfo.unix() < dayjs().unix(), // 是否在当前时间之前
    }
  })
  return res
}

const addMin = dates => {
  var date = dates.setMinutes(dates.getMinutes() + 3)
  // console.log(22,new Date(date),date)
  return formatTimeHour(new Date(date))
}
const addMins = dates => {
  var date = dates.setMinutes(dates.getMinutes() - 0)
  // console.log(22,new Date(date),date)
  return formatTimeHour(new Date(date))
}

module.exports = {
  formatTime,
  formatTimeDay,
  formatTimeHour,
  formatH,
  formatDate,
  formatHS,
  dateListGet,
  addMin,
  addMins,
  formatHt,
  formatDates
}